package com.sskj.market.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.market.bean.OrderDetailsBean;
import com.sskj.market.ui.activity.OrderDetailsActivity;

/**
 * Package :com.sskj.market.presenter
 *
 * @author :budou
 * Date :2019/7/25 14:57
 * Describe :订单详情presenter
 * Remark :
 */
public class OrderDetailsPresenter extends BasePresenter<OrderDetailsActivity> {

    public void getOrderInfo(String orderId, OrderDetailsPresenter presenter) {
        httpService.orderDetails(orderId)
                .tag(this)
                .execute(new JsonCallBack<OrderDetailsBean>(presenter,true) {
                    @Override
                    public void onSuccess(Response<OrderDetailsBean> response) {
                        mView.getDetailsSuccess(response.body());
                    }
                });

    }

    public void cancelOrder(String orderId, OrderDetailsPresenter presenter) {
        httpService.orderCancel(orderId)
                .execute(new JsonCallBack<HttpData>(presenter,true) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        mView.cancelSuccess();
                    }
                });
    }

    public void deleteOrder(String orderId, OrderDetailsPresenter presenter) {
        httpService.orderDelete(orderId)
                .execute(new JsonCallBack<HttpData>(presenter,true) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        mView.deleteSuccess();
                    }
                });

    }

    public void ensureOrder(String orderId, OrderDetailsPresenter presenter) {
        httpService.orderEnsure(orderId).execute(new JsonCallBack<HttpData>(presenter) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                ToastUtil.showShort(response.body().getMsg());
                mView.ensureSuccess();
            }
        });
    }

    public void payOrder(String sn, String pwd, OrderDetailsPresenter presenter) {
        httpService.orderPay(sn, pwd).execute(new JsonCallBack<HttpData>(presenter,true) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                mView.paySuccess();
            }

        });
    }
}
